package com.lanou.zakerproject.subscribe;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.zakerproject.R;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/15.
 */
public class MainAdapter extends FragmentPagerAdapter {



    private ArrayList<Fragment> data;
    private Context context;

    private String titles[] = {"订阅","热点","玩乐","社区"};
    private int imageview[] = {R.drawable.selector_subscribe,
            R.drawable.selector_hotsport,R.drawable.selector_disport,R.drawable.selector_community};


    public MainAdapter(FragmentManager fm,ArrayList<Fragment> data,Context context) {
        super(fm);
        this.context = context;
        this.data = data;
    }

    @Override
    public Fragment getItem(int position) {
        return data.get(position);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    //加图片，绑定tab

    public View getTabView(int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.tab_main, null);
        TextView textView = (TextView) view.findViewById(R.id.tab_tv);
        ImageView imageView = (ImageView) view.findViewById(R.id.tab_img);
        textView.setText(titles[position]);
        imageView.setImageResource(imageview[position]);
        return view;
    }
}
